#include "LogicManager.h"
#include <iostream>

LogicManager::LogicManager(irr::ITimer *timer)
{
	_timer = timer;
	_last_time = timer->getTime();
}

void LogicManager::updateAll()
{
	irr::u32 current_time = _timer->getTime();
        irr::core::map<irr::s32, ILogicNode* >::Iterator it = _nodes.getIterator();
	while(!it.atEnd())
	{
		((ILogicNode *)it->getValue())->update(current_time, _last_time);
		it++;
	}

	_last_time = current_time;
}
void LogicManager::add(ILogicNode *node, irr::s32 name)
{
	_nodes[name] = node;
	irr::scene::ISceneNode *sn = node->getSceneNode();
	if (sn != NULL)
	{
		sn->setID(name);

	}
}

ILogicNode* LogicManager::getNodeFromID(irr::s32 id)
{

	if(_nodes.find(id) != 0)
	{
		return _nodes.find(id)->getValue();
	}
	return NULL;
}

